package hotciv.common;

import hotciv.framework.*;

public class UnitImpl implements Unit {

	private String unitType;
	private Player owner;
	private int moveCount = 1;
	private boolean isMovable = true;
	private int bonusDefensiveStrength;
	private int defensiveStrength;
	private int attackStrength;
	
	/**
	 * Constructor with regular attack and defensive strategies
	 * @param o The owner of the unit
	 * @param ut The type of the unit
	 */
	public UnitImpl(Player o, String ut) {
		assignsInConstructor(o, ut);
	}
	
	/**
	 * Does common assignments to class fields
	 * @param o
	 * @param ut
	 */
	private void assignsInConstructor(Player o, String ut) {
		owner = o; 
		unitType = ut;
	}
	
	@Override
	public String getTypeString() {
		return unitType;
	}

	@Override
	public Player getOwner() {
		return owner;
	}

	@Override
	public int getMoveCount() {
		return moveCount;
	}
	
	/**
	 * Sets this unit's move count to mc.
	 * @param mc the move count the unit should have.
	 */
	public void setMoveCount(int mc) {
		moveCount = mc;
	}

	@Override
	public int getDefensiveStrength() {
		if(unitType.equals(GameConstants.ARCHER)) defensiveStrength = 3;
		else if(unitType.equals(GameConstants.LEGION)) defensiveStrength = 2;
		else if(unitType.equals(GameConstants.SETTLER)) defensiveStrength = 3;
		return defensiveStrength + bonusDefensiveStrength;
	}

	@Override
	public int getAttackingStrength() {
		if(unitType.equals(GameConstants.ARCHER)) attackStrength = 2;
		else if(unitType.equals(GameConstants.LEGION)) attackStrength = 4;
		else if(unitType.equals(GameConstants.SETTLER)) attackStrength = 0;
		return attackStrength;
	}

	/**
	 * Restores the move count to the default value
	 */
	public void restoreMoveCount() {
		setMoveCount(1);
	}
	
	/**
	 * sets the movabillity of a this unit
	 * @param mov
	 */
	public void setMovable(boolean mov) {
		isMovable = mov;
	}
	
	/**
	 * returns the movability of this unit
	 * @return movability of the unit
	 */
	public boolean isMovable() {
		return isMovable;
	}

	/**
	 * @param bonusDefensiveStrength the bonusDefensiveStrength to set
	 */
	public void setBonusDefensiveStrength(int bonusDefensiveStrength) {
		this.bonusDefensiveStrength = bonusDefensiveStrength;
	}

}
